package com.lovo.pz.role;

import com.lovo.pz.util.GameUtil;
import com.lovo.pz.window.GamePanel;

import java.awt.*;
/**
 * 太阳花角色
 * @author 白德柯
 *
 */
public class SunFlowerRole extends PlantRole{
    public SunFlowerRole(Component component){
        super(component);
    }
    @Override
    public void initRole() {
        setHp(10);
        setCost(50);
        setPlantType(PlantCardRole.SUN_FLOWER);
        setRoleWidth(GameUtil.sunFlowerImage.getWidth(getComponent()));
        setRoleHeight(GameUtil.sunFlowerImage.getHeight(getComponent()));
    }

    @Override
    public void paintRole(Graphics g) {
        // 开启半透明
        if(getRunStatus() == PLANT_TEMP){
            GameUtil.setAlpha(g,0.5f);
        }
        g.drawImage(GameUtil.sunFlowerImage,getRoleX(),getRoleY(),getComponent());
        // 关闭半透明
        GameUtil.setAlpha(g,1);
    }

    @Override
    public void action() {
        if(getRunStatus() == SEND_BULLET){
            // 每隔多少时间发射一个子弹
            if(GameUtil.delay(5000,this,"sendSunFlowerBullet")){
                SunSeedRole sunSeedRole = new SunSeedRole(getComponent());
                sunSeedRole.setRoleX(getRoleX());
                sunSeedRole.setRoleY(getRoleY());
                GamePanel gamePanel = (GamePanel) getComponent();
                gamePanel.getSunSeedRoleList().add(sunSeedRole);
            }
        }
    }
}
